/*
 * Copyright 1999-2004 Alibaba.com All right reserved. This software is the confidential and proprietary information of
 * Alibaba.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Alibaba.com.
 */
package action.expr.ast;

import action.expr.ActionVisitor;
import action.expr.VisitableAction;

/**
 * ������ʽ
 * 
 * @author pf-miles 2011-6-17 ����03:30:20
 */
public class Expr implements VisitableAction {

    private Addend left;
    private OpLevel1 op;
    private Addend right;
    private Addend single;
    private boolean quoted;

    public void accept(ActionVisitor visitor, Object... params) {
        visitor.visitExpr(this, params);
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (quoted) {
            sb.append("(");
        }
        if (this.single != null) {
            sb.append(single.toString());
        } else {
            sb.append(left + " " + op + " " + right);
        }
        if (quoted) {
            sb.append(")");
        }
        return sb.toString();
    }

    public Addend getLeft() {
        return left;
    }

    public void setLeft(Addend left) {
        this.left = left;
    }

    public OpLevel1 getOp() {
        return op;
    }

    public void setOp(OpLevel1 op) {
        this.op = op;
    }

    public Addend getRight() {
        return right;
    }

    public void setRight(Addend right) {
        this.right = right;
    }

    public Addend getSingle() {
        return single;
    }

    public void setSingle(Addend single) {
        this.single = single;
    }

    public boolean isQuoted() {
        return quoted;
    }

    public void setQuoted(boolean quoted) {
        this.quoted = quoted;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((left == null) ? 0 : left.hashCode());
        result = prime * result + ((op == null) ? 0 : op.hashCode());
        result = prime * result + (quoted ? 1231 : 1237);
        result = prime * result + ((right == null) ? 0 : right.hashCode());
        result = prime * result + ((single == null) ? 0 : single.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Expr other = (Expr) obj;
        if (left == null) {
            if (other.left != null)
                return false;
        } else if (!left.equals(other.left))
            return false;
        if (op == null) {
            if (other.op != null)
                return false;
        } else if (!op.equals(other.op))
            return false;
        if (quoted != other.quoted)
            return false;
        if (right == null) {
            if (other.right != null)
                return false;
        } else if (!right.equals(other.right))
            return false;
        if (single == null) {
            if (other.single != null)
                return false;
        } else if (!single.equals(other.single))
            return false;
        return true;
    }

}
